<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="../common/common.jsp"%>
<title>操作员修改密码</title>
</head>
<body>
<article class="page-container">
    <form class="form form-horizontal">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>旧密码：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <input type="text" class="input-text" value="" placeholder="" id="oldPassword" name="oldPassword">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>新密码：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <input type="text" class="input-text" value="" id="newPassword" name="newPassword">
            </div>
        </div>
		<div class="row cl">
		    <div class="formControls col-xs-8 col-xs-offset-3">
		         <input name="code" class="input-text size-L" type="text" placeholder="验证码" id="code" style="width:235px;">
		         <a id="codeSend" class="btn btn-primary radius">获取验证码</a>
		    </div>
		 </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-8 col-xs-offset-4 col-sm-offset-3">
                <a class="btn btn-primary radius size-l" id="submit"><i class="Hui-iconfont">&#xe632;</i> 提交</a>
            </div>
        </div>
    </form>
</article>

<script type="text/javascript">
$(document).ready(function () {
	 var id = "${id}";
	 $('#submit').click(function () {
		var oldPassword = $("#oldPassword").val();
		var newPassword = $("#newPassword").val();
		var code = $("#code").val();
		$.ajax({
			type : 'POST',
			url : ctx + '/operatorManage/alterPassword.do',
			data : {
				id : id,
				oldPassword : oldPassword,
				newPassword : newPassword,
				code : code
			},
			dataType : 'json',
			timeout : 30000,
			context : $('body'),
			success : function(data) {
				if (data.code == "ok") {
	                   layer.msg("操作成功!", {icon: 6, time: 1000}, function () {
	                      	layer_close();
	                      	window.location.href= ctx + "/index.html";
	                   });
					} else {
						 layer.msg(data.msg, {icon: 5, time: 2000});
					}
			},
			error : function(xhr, type) {
				layer.msg('操作失败!', {icon: 5, time: 2000});
			}
		});
		  return false;
	 });
	 
	 $('#codeSend').click(function () {
		 sendEmail();
	 });
	 function sendEmail(){
			$.ajax({
				type : 'POST',
				url : ctx + '/operatorManage/sendEmailCode.do',
				data : {
					operatorId : id
				},
				dataType : 'json',
				timeout : 30000,
				context : $('body'),
				success : function(data) {
					if (data.code == "ok") {
						 layer.msg('验证码已经发送到您的邮箱，请注意查收!', {icon: 6, time: 2000});
					} else {
						layer.msg(data.msg, {icon: 5, time: 2000});
					}
				},
				error : function(xhr, type) {
					layer.msg('操作失败!', {icon: 5, time: 2000});
				}
			});
		}
});
</script>
</body>
</html>